home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
public
/
Xprof
/
xprof
/
update.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
7KB
|
204 lines
/*==================================================================
* File : update.c
* Package: Xprof
*
* Author : Aloke Gupta.
*
* (C) Copyright 1992, Aloke Gupta.
*==================================================================*/
/*
* update_profile(int index, Xattributes *attributes)
* print_profile_stats();
*/
#include <stdio.h>
#include <X11/Xproto.h>
#include "common.h"
#include "profile.h"
extern MsgStats RequestStats[];
extern MsgType RequestType [];
/* The following times are maintained in milliseconds */
static ProfileStats profilestats[MAXREQUESTS];
/* Functions to update above profilestats */
enter_net_time(index, time)
int index; double time;
{
profilestats[index].net_time += (double) time;
profilestats[index].total_time += (double) time;
}
enter_cpu_time(index, time)
int index; double time;
{
profilestats[index].cpu_time += (double) time;
profilestats[index].total_time += (double) time;
}
/* init_profile: Initialize the profilestats data structure */
init_profile()
{ int i;
for (i = 0; i < MAXREQUESTS; i++) {
profilestats[i].net_time = 0;
profilestats[i].cpu_time = 0;
profilestats[i].total_time = 0;
profilestats[i].cpu_valid = VALID; /* Mark it valid by default */
}
}
/*
* update_profile: Make entries in the data structures for network time and
* server computation time.
*/
update_profile(index, attributes)
int index; /* Index-number of request */
Xattributes *attributes; /* Attributes of the message */
{
double net_time=0.0;
double cpu_time=0.0;
/*
* First update the network time for this function
*/
if (attributes->bytes != -1) {
/* Network Speed contribution */
net_time = (double) 1000.0 * attributes->bytes / get_net_speed();
enter_net_time(index, net_time);
/* Network Latency contribution */
switch (index) { /* Only counted for round-trip requests */
case X_GetWindowAttributes: /* 3 */
case X_GetGeometry: /* 14 */
case X_QueryTree: /* 15 */
case X_InternAtom: /* 16 */
case X_GetAtomName: /* 17 */
case X_GetProperty: /* 20 */
case X_ListProperties: /* 21 */
case X_GetSelectionOwner: /* 23 */
case X_GrabPointer: /* 26 */
case X_GrabKeyboard: /* 31 */
case X_QueryPointer: /* 38 */
case X_GetMotionEvents: /* 39 */
case X_TranslateCoords: /* 40 */
case X_GetInputFocus: /* 43 */
case X_QueryKeymap: /* 44 */
case X_QueryFont: /* 47 */
case X_QueryTextExtents: /* 48 */
case X_ListFonts: /* 49 */
case X_ListFontsWithInfo: /* 50 */
case X_GetFontPath: /* 52 */
case X_GetImage: /* 73 */
case X_ListInstalledColormaps: /* 83 */
case X_AllocColor: /* 84 */
case X_AllocNamedColor: /* 85 */
case X_AllocColorCells: /* 86 */
case X_AllocColorPlanes: /* 87 */
case X_QueryColors: /* 91 */
case X_LookupColor: /* 92 */
case X_QueryBestSize: /* 97 */
case X_QueryExtension: /* 98 */
case X_ListExtensions: /* 99 */
case X_GetKeyboardMapping: /*101 */
case X_GetKeyboardControl: /*103 */
case X_GetPointerControl: /*106 */
case X_GetScreenSaver: /*108 */
case X_ListHosts: /*110 */
case X_SetPointerMapping: /*116 */
case X_GetPointerMapping: /*117 */
case X_SetModifierMapping: /*118 */
case X_GetModifierMapping: /*119 */
enter_net_time(index, (double) get_net_latency());
break;
default: /* All other requests are one-way */
break;
} /* switch(index) */
}
/*
* Now update the cputime for this request
*/
if ((attributes->size!=-1)&&(profilestats[index].cpu_valid!=INVALID)) {
cpu_time = (double) get_request_time(index, attributes);
if (cpu_time != -1.0) {
cpu_time *= 1000.0; /* ms */
enter_cpu_time(index, cpu_time);
}
/* Else mark the cpu time invalid */
else profilestats[index].cpu_valid = INVALID ;
}
}
static char *profile_header[] = {
"_____________________________________________________________________________",
"Request Time % of Compute Network No. of % of Time/call",
" Name (ms) total part(%) part(%) msgs total (ms)",
};
/* The following functions uses the RequestStats[] and RequestType[] structure
* in addition to the profilestats structure maintained in this file.
*/
print_profile_stats(fp)
FILE *fp;
{
int i;
long total_num = 0;
double total_net_time = 0.0;
double total_cpu_time = 0.0;
double total_total_time= 0.0;
fprintf(fp, "\n \t\t***** Execution Profile *****\n");
/* Print Network details */
if (get_net_speed() == MAXDOUBLE)
fprintf(fp,"\nNetwork speed = Infinity,");
else fprintf(fp,"\nNetwork speed = %.2lf Kbytes/sec,",
(double) get_net_speed() / 1000.0);
fprintf(fp," latency = %.2lf ms\n", (double) get_net_latency());
/* Accumulate totals */
for (i = 0; i < MAXREQUESTS; i++)
if (RequestStats[i].invoked == TRUE) {
total_num += RequestStats[i].number;
total_net_time += profilestats[i].net_time ;
total_cpu_time += profilestats[i].cpu_time ;
total_total_time += profilestats[i].total_time;
}
/*
* Print the header
*/
fprintf(fp,"%s\n", profile_header[0]);
fprintf(fp,"%s\n", profile_header[1]);
fprintf(fp,"%s\n", profile_header[2]);
fprintf(fp,"%s\n", profile_header[0]);
/*
* Print the statistics
*/
for (i = 0; i < MAXREQUESTS; i++)
if (RequestStats[i].invoked == TRUE) {
fprintf(fp,"%-22s", RequestType[i].name);
fprintf(fp,"%10.3lf " , profilestats[i].total_time);
fprintf(fp,"%5.2lf%% ",
(double) 100.0 * profilestats[i].total_time / total_total_time);
if (profilestats[i].cpu_valid == VALID)
fprintf(fp,"%5.2lf%% ",
(double) 100.0 * profilestats[i].cpu_time / total_total_time);
else fprintf(fp," N/C ");
fprintf(fp,"%5.2lf%% ",
(double) 100.0 * profilestats[i].net_time / total_total_time);
fprintf(fp,"%6ld " , RequestStats[i].number);
fprintf(fp,"%5.2lf%% ",
(double) 100.0 * RequestStats[i].number / total_num);
fprintf(fp,"%7.3lf\n",
(double) (profilestats[i].total_time / RequestStats[i].number));
}
fprintf(fp,"%s\n", profile_header[0]);
fprintf(fp,"%22s%10.3lf %5.1lf%% %5.2lf%% %5.2lf%% %6ld %5.1lf%% %7.3lf\n",
"Grand Total ",
total_total_time,
100.0,
(double) 100.0 * total_cpu_time / total_total_time,
(double) 100.0 * total_net_time / total_total_time,
total_num,
100.0,
(double) total_total_time / total_num);
fprintf(fp,"%s\n", profile_header[0]);
}